var express = require('express');
const db = require("../db");
var router = express.Router();

/* GET home page. */
router.post('/', function(req, res, next) {
    // 允许CORS跨域的域名
    res.setHeader('Access-Control-Allow-Origin', '*')
    // 允许CORS跨域的请求方式，默认只有GET,POST
    res.setHeader('Access-Control-Allow-Methods', 'GET,POST,PUT,PATCH,DELETE')
    // 允许CORS跨域请求的请求头
    res.setHeader('Access-Control-Allow-Headers', 'content-type')
    console.log(req.body.code)
    let code = req.body.code
    const sql = `UPDATE code SET code=${code} WHERE id=1`
    db.query(sql, (err, data) => {

        if (err) {
            return res.send({code: 400, error: err})
        }
        return res.send({
            code: 200,
            message: 'ok',
            data: data
        })
    })

});

module.exports = router;
